package com.zzyl.nursing.controller.member;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.zzyl.nursing.domain.Order;
import com.zzyl.nursing.service.OrderService;
import com.zzyl.serve.domain.NursingProject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/member/orders")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/project/page")
    public Map<String, Object> getOrders(
            @RequestParam(required = false) String name,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required = false) Long status) {
        PageInfo<NursingProject> pageInfo = orderService.getOrders(name, pageNum, pageSize, status);

        Map<String, Object> response = new HashMap<>();
        response.put("total", pageInfo.getTotal());
        response.put("rows", pageInfo.getList());
        response.put("code", 200);
        response.put("msg", "查询成功");

        return response;
    }

    /**
     *  根据编号查询护理项目信息
     */
    @GetMapping("/project/{id}")
    public Map<String, Object> getOrderById(@PathVariable Long id) {
        NursingProject order = orderService.getOrderById(id);

        Map<String, Object> response = new HashMap<>();
        if (order != null) {
            response.put("data", order);
            response.put("code", 200);
            response.put("msg", "操作成功");
        } else {
            response.put("code", 404);
            response.put("msg", "未找到该护理项目");
        }

        return response;
    }


}